#ifndef __ConsumerThread_H__
#define __ConsumerThread_H__

#include "Thread.hpp"
#include "TaskQueue.hpp"

#include <stdio.h>
#include <unistd.h>

class ConsumerThread
: public wd::Thread
{
public:
    ConsumerThread(wd::TaskQueue & que)
    : _taskque(que)
    {}


private:
    //消费者线程要从任务队列中取数据
    void run() override
    {
        int cnt = 20;
        while(cnt-- > 0) {
            int number = _taskque.pop();
            printf("Consumer consume a number: %d\n", number);
            //消费者1秒钟才取一个数据
            sleep(1);
        }
    }

private:
    wd::TaskQueue & _taskque;
};

#endif

